<?
$title = 'File Uploads';
include("includes/functions.php");
include("includes/sajax/functionsSajax.php");
include("includes/sajax/sajax.php");

sajax_init();
$sajax_request_type = "POST";
sajax_export("deleteFile");
sajax_handle_client_request();

include("includes/header.php"); 

// Get all files uploaded
$sql = "SELECT CU.FID,CU.PID,CU.FileName,CU.FileNotes,CU.FileType,CU.DateUpload,CP.ProgramName,CP.County
		FROM casa_uploads CU
		LEFT JOIN casa_programs CP ON CP.PID = CU.PID
		ORDER BY CP.ProgramName,CU.DateUpload DESC";
$result = mysql_db_query($dbname,$sql);
$rows = mysql_num_rows($result);

if ($rows>0) {
	// Render file table
	echo '<table class="dataTable" style="width: 100%;">';
	echo '<tr>';
		echo '<th style="width: 5%;"></th>';
		echo '<th style="width: 10%;">Download</th>';
		echo '<th style="width: 30%;">Program</th>';		
		echo '<th style="width: 40%;">Notes</th>';
		echo '<th style="width: 15%;">Date Submitted</th>';
	echo '</tr>';
	
	$i=0;
	while ($value = mysql_fetch_assoc($result)) {
		$fID        = $value[FID];
		$program    = $value[ProgramName];
		$county     = $value[County];
		$fileName   = $value[FileName];
		$fileType   = $value[FileType];
		$fileNotes  = $value[FileNotes];
		$dateUpload = mysql_to_date2($value[DateUpload]);
		
		if ($fileType == 'excel') {
			$fileIcon = 'iconExcel.gif'; 
		} elseif ($fileType == 'word') {
			$fileIcon = 'iconWord.gif';
		}
		
		if (($i % 2) > 0) { $class = 'noRowClass'; }
			else { $class = "altRow"; }
		
		echo '<tr id="fileRow'.$fID.'" class="'.$class.'">';
			echo '<td style="text-align: center;"><a href="#" onClick="confirmDelete(\''.$fID.'\',\'file\'); return false;"><img src="images/iconDelete.gif" style="border: none;" alt="Delete this file" /></a></td>';
			echo '<td style="text-align: center;" title="Download File: '.$fileName.'"><a href="uploads/'.$fileName.'"><img src="images/'.$fileIcon.'" style="border: none;" alt="Download File: '.$fileName.'" /></a></td>';
			echo '<td style="vertical-align: top;">'.$program.' ['.$county.']</td>';		
			echo '<td style="vertical-align: top;">'.$fileNotes.'</td>';
			echo '<td>'.$dateUpload.'</td>';
		echo '</tr>';
		$i++;
	}
	
	echo '</table>';
}
?>


<br />
<? include("includes/footer.php"); ?>		